<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>支付表收款机构维护</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar" method="POST">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
        		<div class="fieldBox">
	                <div class="label">支付表号</div>
	                <div class="field">
	                    <input name="paySchCode" id="paySchCode"  type="text" class="ui-textbox"   ligerui="width: 160">
	                </div>
	            </div>
        		<div class="fieldBox">
	                <div class="label">融资机构名称</div>
	                <div class="field">
	                    <input name="insNm" id="insNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">项目名称</div>
	                <div class="field">
	                    <input name="fncPrjNm" id="fncPrjNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">起租日</div>
	               <div class="field">
		                        <input ligerui="width: 82" name="startTmB" id="startTmB" type="text" class="ui-datepicker" value="">
		                        -
		                        <input ligerui="width: 82" name="startTmE" id="startTmE" type="text" class="ui-datepicker" value="">
		           </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">状态</div>
	                <div class="field">
	                    <select name="stCd" id="stCd" ligerui="width: 160">
	                        <option value="" seleted>请选择</option>
	                        <c:forEach items="${stCdLst}" var="rePyTpCd">
	                        	<option value="${rePyTpCd.key }">${rePyTpCd.value }</option>
	                        </c:forEach>
	                    </select>
	                </div>
	            </div>
            </div>
            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <span id="exportBtn" class="sq-button-round">导出</span>
	               
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid">
</div>

<script type="text/javascript">
	var grid = null;
	$("#clearBtn").click(function(event) {
	    $("#resetBtn").click();  //重置 input-text
	    var form = liger.get("searchBar");
	    form.setData({  //重置select等特殊表单
	        "paySchCode": "",
	        "insNm": "",
	        "fncPrjNm": "",
	        "startTmB": "",
	        "startTmE": "",
	        "stCd": ""
	    });
	});
	$(function () {
		initInstLstForm();
		initGrid();
	    initForm();
		initEvent();
	});
	function initForm(){
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    grid.options.isSingleCheck=true;	
		$("#searchBar").ligerForm();
	}
	
	function initEvent(){
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (var name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
	
	function initGrid(){
		$("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbase/fncPrjPayIns/initList.do',
	    	method : 'get',
	        columns: [
	            { display: '支付表号', name: 'paySchCode', width: 150 , align:'center', enabledSort:true},
	    	    { display: '承租人名称', name: 'cstNm', width: 150, enabledSort:true },
	            { display: '融资机构', name: 'insNm', width: 150, enabledSort:true,
	    	    	render: function (rowdata, rowindex, value, column) { 
	    	    		var h='<a href="javascript:detailJG(';
	            		h+="'"+rowdata.insId+"'";
	                    h+=')">'+value+'</a>';
	                        return h;
	    	    	}	
	            },
	            { display: '再融资项目', name: 'fncPrjNm', width: 150 , enabledSort:true,
						render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.fncPrjId+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
						}
	            },
	            { display: '商户号', name: 'bizNo', width: 100,enabledSort:true},
	            { display: '起租日', name: 'startTm', width: 100 , render:renderDate, enabledSort:true},
	            { display: '创建时间', name: 'crtTm',width:100, render:renderDate, enabledSort:true},
	            { display: '赎回时间', name: 'shTm', width: 100 ,render:renderDate, enabledSort:true},
	            { display: '状态', name: 'stCdNm',width:100,enabledSort:true}
	        ],
	        pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(200);	
	}
	function detailJG(id){
		    Add_navTab('tab_project_detail'+id,'机构信息详情','<%=path%>/rfbase/fribaseinfo/toDetailPage.do?id='+id);
	}
	function detailBtn(id){
			Add_navTab('tab_project_detail'+id,'项目基本信息详情','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage1.do?id='+id);
	}

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function initInstLstForm(){
		$("#insId").ligerComboBox({ 
		        url:'<%=path%>/rfbase/fncprjpaysch/initInstList.do',
		        ajaxType :'GET', 
		        valueField: 'id', textField: 'fundRasInsNm',
				columns: [
	                { header: '机构编号', name: 'id', width: 140 }, 
	                { header: '机构名称', name: 'fundRasInsNm', width: 120 },
	            ], 
	            width: 200,
	            selectBoxWidth: 480, 
	            selectBoxHeight: 240
	        });
	}
	
  	function startRepay(payschid,pid,repaystcd,betwndays){
  		if(betwndays!=null && Number(betwndays)>15){
  			//alert("还款日15日内方可发起还款,当前距离还款日天数："+betwndays);
  			//return;
  		}
		var callback = function(){
			 grid.reload();
		}
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_prj_pay_sch_start'+timestamp,'还款申请',
				'<%=path%>/rfbase/fncprjpaysch/toRepayPage.do?payschid='+payschid+'&pid='+pid+'&repaystcd='+repaystcd,callback);
  	}
	//导出
	$("#exportBtn").click(function(event) {
		var form = liger.get("searchBar");
		var data = form.getData();
		
		var url = '<%=path%>/rfbase/fncPrjPayIns/exportExcel.do';
		$('#searchBar').attr('action', url);  
        $('#searchBar').submit();

	})

</script>
</body>
</html>